ChatGPT and scripting

OK, I’m diving into this- we just got a handful of seats to ChatGPT Enterprise. We can now load and use proprietary IP in ChatGPT, and it is siloed, and not being used outside our sandbox.

Now- I know very little about scripting, programming, coding. Last code I wrote was hacking out HTML 1.0 on a beige mac G3 and cheered when my / tags worked. Anyway-

Here are some points-

  • Don’t have the time to go super deep into Python. I can do some hours of Python basics classes, but full time degree stuff is not possible.
  • Education like “how to write coding prompts for AI” is great, no idea on resources for this with a focus on Keyshot style scripting though. Open to this.
  • Goal to be able to co-create scripts with ChatGPT to improve useability, functionality and workflow in KS in regards to importing and naming, setting up scenes, aligning and distributing objects, dealing with duplicate materials, automating cleanup of scenes and creating ksp packages with out doing it manually (open KS, run a script that will ask for a project, and end with a ksp file in the same directory that is autonamed with the original project’s name and appended with “archive” and the date in the filename.
    -No need for headless render control so far, and the majority of my scripts will be “utility” based while in the app, nothing like “here’s a folder of stp files, render each at 4 angles with these 5 materials and save as psd files”. All our projects need human touches.

I know a lot of what I’m asking is doable in a more manual way, but doing this sort of thing a lot, automating this stuff will save time and make it less cumbersome to use the app, multiply that by the three of us on our team and it adds up.

That being said, I really think that cracking open the scripting side of things for the non-coding user would be huge, and open the floodgates of people sharing and writing scripts. Seems like AI is almost there, its just doesn’t work.

I have found Don Tuttle’s GPT for keyshot, but it doesn’t seem to know anymore than my own custom GPT does. And ChatGPT won’t store any data about the KS lux modules from session to session, and it won’t autoload/reference or in any way set itself up in a new session by autoloading any material. And now that I have Enterprise, our admin has restricted any non-corporate owned GPT’s so I can’t even access Don’s GPT anyway.

I’ll probably end up with 2 GPT accounts, one enterprise, one personal. That way I can access Don’s GPT with my personal account and use the Enterprise one when I need it. A

Any other general AI scripting advice for an AI/scripting newbie? Python for Dummies book is in my amazon cart, so I’m going to start the education process soon, just want to know which direction and what resources to use to direct my learning towards KS as much as possible.

I’ll tag in @don.tuttle here in case he has some good tips!

@matt.gerard I learned HTML 1.0 in a beige mac G3 too! Then Dreamweaver came out.

What I’ve learned making a few GPTs specifically for python scripting:

  • KeyShot uses a built-in version of python it’s unique.

  • AI LLMs assume they know everything about python. So often they don’t even bother with your detailed instructions. It reads “Python” skips any instructions or knowledge files and creates a Python script that isn’t compatible with KeyShot. ChatGPT, Claude, Gemini, Grok all the same. I had hopes for Claude it understands that KeyShot Python differs, but it fails too.

  • I printed out all the Python commands and added them to a text document that I use as a reference to double check the AI to ensure it’s using the proper code.

There are almost always issues with:

  1. KeyShot Python Constraints

  2. KeyShot Python Custom Input Dialog - lux.getInputDialog()

  3. Accessing the Scene tree - lux.getSceneTree()

  4. Node TYPE Constants -
    NODE_TYPE_ANIMATION = 3
    NODE_TYPE_GROUP = 1
    NODE_TYPE_MODEL = 5
    NODE_TYPE_MODEL_SET = 4
    NODE_TYPE_OBJECT = 2

getNodesFromType(…),
getKind(…) Get node kind.

  1. Node types - lux.NODE_TYPE_GROUP, lux.NODE_TYPE_OBJECT, lux.NODE_TYPE_ANIMATION, lux.NODE_TYPE_MODEL_SET, and lux.NODE_TYPE_MODEL default = all types).

  2. Hide/Show (Visibility) - hide(…), isHidden(…), getHidden(…), show(…)

  3. getChildren(…) - only works on groups

  4. Node IDs are dynamic - getID(…) Get node ID.

  5. Node Names are static - getName(…) Get node name.

  6. getSceneTree(…) - Get lux.SceneNode object representing the root of the scene tree.

  7. Dictionaries - opts = Options specified as a dictionary (see lux.getImportOptions()).
    Opts:

In KeyShot scripting, the opts variable often refers to a set of options or settings that can be configured for various operations, such as rendering, importing files, and exporting data. These options are typically stored in a Python dictionary or an object that allows for the customization of behavior and parameters of a given function. Below are examples of some commonly used opts in different contexts within KeyShot scripting:

Rendering Options:
When configuring render settings, opts may include parameters to control aspects of the rendering process, such as resolution, quality, and format. Here’s an example of setting up render options:

Import Options:
For importing geometry or scenes into KeyShot, opts can specify how the import process behaves, such as whether to center the geometry, scale it, or how to handle existing materials:

Image Render Options:
For image rendering, opts can include detailed settings about the output image, such as file format, DPI, and whether to include alpha channels:

  1. Import vs Load - importMaterials(…)
    Imports materials from a MTL or KMP file into material library. Note: It is required that resource libraries are loaded once per session - the operation blocks while loading.
    file = MTL/KMP file path to import materials from. *
    loadMaterials(…)
  • Loads materials from MTL file as in-project materials, i.e. they will not show up in the material library visually.
    file = MTL File path to load materials from. *
  1. New (KS) vs Create (Python) - newModelSet(…), newScene(…), newImageStyle(…), newEnvironment(…), newCamera(…)

  2. Remove (KS) vs Delete (Python) - removeCamera(…), removeEnvironment(…), removeImageStyle(…), removeModelSet(…)

  3. Set Active - setActiveEnvironment(…), setActiveImageStyle(…), setActiveStudio(…), setCamera(…),

  4. Camera Look-at (KS) vs Target (Python) - getCameraLookAt(…), setCameraLookAt(…)

17… You can only script a Spherical Camera. Absolute Camera is busted.

  1. Thumbnails are not what you think they are. Specific to the Material Information Manager.

  2. Duplicate (KS) vs Copy (Python) - duplicate(…)
    Duplicate current node and subtree. amount = The amount of duplicates to create (default = 1).
    obj.duplicate(), dup.applyTransform()

  3. Get vs Find -

  • find(…) Find nodes in the subtree of this node by searching part names and material names. If no names or materials are given then it will find everything.
    name = Part name to search for (string/tuple/list).
    mat = Material name to search for (string/tuple/list).
    all = Match all part names or all material names (default = false).

  • getMaterial(…) Get material of a node.
    getName(…) Get node name.
    getParent(…) Get parent node of this node.
    getPath(…) Get path from root to this node as a tuple of lux.SceneNode objects.
    text = Whether to return the names instead of lux.SceneNode objects (default = false).
    getRenderLayer(…) Get render layer for associated node, if any.
    getSelected(…) Get selected nodes of a group (recursive).
    getTransform(…) Get the transformation matrix of this node.
    getBoundingBox(…) Get bounding box of node as a tuple of two vectors: min and max.
    world = Whether to be in world space or not (default = false).
    getCenter(…) Get the center of this node.
    world = Whether to be in world space or not (default = false).
    getChildren(…) Get children of group.

  1. setName(…)
  2. Material Graph manipulation is it’s own thing, AI fails without specific instructions and understanding of Node Names and Node IDs.
  3. Material Shaders - Classes, Functions, Shader PARAMETERS, and Shader TYPES all MUST be defined.
  4. Resource Libraries Folders:
    #Set the KeyShot “Resources Library” path based on the operating system.
    Windows
    ** library_path = “C:\Users\Public\Documents\KeyShot 12”**
    MacOS and Unix
    ** library_path = “/Library/Application Support/KeyShot 12”**
    Library Constants
    FOLDER_ANIMATIONS = 8
    FOLDER_BACKPLATES = 3
    FOLDER_COLORS = 9
    FOLDER_CONFIG_ROOT = 14
    FOLDER_DOWNLOADS = 16
    FOLDER_ENVIRONMENTS = 5
    FOLDER_EXTERNAL_PLUGIN = 13
    FOLDER_FAVORITES = 11
    FOLDER_MATERIALS = 7
    FOLDER_MATERIAL_TEMPLATES = 10
    FOLDER_MODELS = 15
    FOLDER_RESOURCE_ROOT = 1
    FOLDER_SCENES = 6
    FOLDER_SCREENSHOTS = 2
    FOLDER_SCRIPTS = 12
    FOLDER_TEXTURES = 4

KeyShot 2024.1 Python Scripting Common ChatGPT Errors:

GUI Considerations:

  • Non-Empty Default Values for lux.getInputDialog():
    • Ensure all fields, especially lux.DIALOG_TEXT, have non-empty default values to prevent runtime errors.

Common Errors:

  • Empty Item Tuple Exception:

    • Error: Exception: Items of item tuple must be specified!
    • Cause: Incomplete or improperly formatted tuple for lux.getInputDialog().
    • Solution: Ensure completeness and correct formatting of tuples.
  • Type Mismatch Error:

    • Error: TypeError: argument 1 must be str, not list
    • Cause: Function expects a string argument but receives a list or other types.
    • Solution: Review function calls to ensure arguments are of the expected type.

Implementation Tips:

  • Use print statements or logging for debugging.
  • Implement explicit type checks or use Python’s type hinting.
  • Double-check the consistency and completeness of tuples.

Material Graph:

  • KeyShot scripting involves using the correct functions in the lux module for accessing and manipulating materials.

Accessing Material Graphs and Handling Errors:

  • Function to Use: lux.getMaterialGraph(name) to get a material graph.
  • Common Errors: AttributeErrors due to incorrect function calls.
  • Solutions: Use correct lux module functions like lux.getMaterialGraph(name).

Correcting Misused Functions:

  • Incorrect Use: Using lux.getMaterial() or lux.getMaterials() which are not valid.
  • Correction: Use the correct functions like lux.getSceneMaterials().

Camera:

KeyShot Scripting: Correcting Camera Access Error:

  • Error: AttributeError: module ‘lux’ has no attribute ‘getActiveCamera’ indicates using a non-existent function.
  • Correct Usage: Use lux.getCamera() instead of lux.getActiveCamera.
  • Solution: Always consult the KeyShot Python API documentation for correct function usage.

AI makes coding so easy anyone can do it! :upside_down_face:

1 Like

Have you tried something like this Don? I didn’t but I was wondering if using something like GitHub - MaxHastings/Kolo: The Fastest Way to Fine-Tune LLMs Locally to train AI specific on KeyShot’s functions would help. I did run some LLMs local but they had to move since I needed some space :wink:

Nope. I’m on the $20 a month plan. No API access for me.

I meant fine-tuning an existing open source LLM model locally with KeyShot specific features/code. Just like the AI Shots feature which runs locally. Since existing ones lack some understanding of the KS functions.

Think that’s actually the nicest part about AI that it’s available for free. You know a LOT about what goes wrong using different AI models so I thought feeding an open source model with the right knowledge could lead potentially to a LLM inside KS helping you with the Python scripts just like the AI Shots model does with the images.

I totally lack the knowledge of Python and the KS functions but came across that page some time ago and it seemed like a real friendly, well relatively, way to increase accuracy of existing models by fine-tuning.

@oscar.rottink You’re giving me way more credit than I deserve but thank you!

Totally agree, having a true programming environment is a what’s needed. The KeyShot dev team is already on it.

For what it’s worth, I’m just an AI hobbyist doing this on my own. Not involved with KeyShot development beyond sharing feedback… because I’m dangerous. :crazy_face: